const Generator = require('yeoman-generator');
const fs = require('fs-extra');
const path = require('path');

module.exports = class extends Generator {
  constructor(args, opts) {
    super(args, opts);

    this.argument('appName', {type: String, required: true, desc: 'app name'});
  }

  initializing() {
    let appName = this.options.appName;
    let currentDir = this.destinationPath();
    let appDir = path.join(currentDir, appName);

    if (fs.existsSync(appDir)) {
      this.log.error('Directory already existed.');
      process.exit(1);
    }

    fs.ensureDirSync(appDir);
    this.options.appDir = appDir;
  }

  writing() {
    let options = this.options;
    let appDir = options.appDir;
    this.fs.copy(
      this.templatePath('**'),
      this.destinationPath(this.options.appName)
    );
  }

  install() {

  }

  end() {
    this.log('create successful.');
  }

};
